//
//  JigSawMovieButton.m
//  JigSawKiosk
//
//  Created by Stulberg on 10-10-17.
//  Copyright 2010 FruitonLabs. All rights reserved.
//

#import "JigSawMovieButton.h"


@implementation JigSawMovieButton

@synthesize aMovie ;

- (id) initWithObjects:(NSURL*)_movieLocation size:(CGRect)_frameSize pos:(CGPoint)pos{
	self = [super init] ;
	
	if (self) {
		self.bounds = _frameSize ;
		self.position = pos ;
		movieLocation = _movieLocation ;
		[self setupLayers] ;
	}
	return self ;
}

-(void) dealloc {
	[movieLayer release];
	[aMovie release];
	[movieLocation release] ;
	
	[super dealloc] ;
}

- (void) setupLayers {
	//[aMovie release] ;	
	[self setMasksToBounds:YES];
	
	NSError *error ;
	aMovie  = [[QTMovie movieWithURL:movieLocation error:&error] retain] ;
	[aMovie setAttribute:[NSNumber numberWithInt:1] forKey:QTMovieLoopsAttribute] ;
	
	if (aMovie ) {
		
		// create movie layer
		movieLayer = [QTMovieLayer layerWithMovie:aMovie] ;
		// size layer
		//movieLayer.position = pos ;//CGPointMake(200, 200);
		movieLayer.frame = CGRectMake(0, 0, [self bounds].size.width, [self bounds].size.height) ;
		// scale the movie layer with the container (it will resize with the window)
		//movieLayer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
		[self addSublayer:movieLayer] ;
	}
	// start the movie playing
	[aMovie stop];
}


@end
